package com.demo2do.fms.entity.supplier.common;

import java.beans.Transient;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.format.PersistentFormat;

/**
 * 申请人上传各类文件资料
 * 
 * 与supplier关联关系:一对一 
 *
 * @author Wy
 *
 */
@Entity
@Table(name="FMS_SUPPLIER_RECOMMENDATION")
@DynamicUpdate
public class SupplierRecommendation {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 与supplier关联 */
    @ManyToOne(fetch = FetchType.LAZY, optional = true)
    @PersistentFormat
    private Supplier supplier;
    
    /** 备选供应商引入评审申报表上传 */
    private String introduceForm;
    
    /** 现场评审得分结果上传   */
    private String assessment;
    
    /** 推荐函上传  */
    private String recommendation;
    
    /** 创建时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    
    /** 最后修改时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastModifyTime;
    
    /** 创建者 */
    private Long creator;
    
    /** 最后修改者 */
    private Long lastOperator;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    /**
     * The default constructor
     */
    public SupplierRecommendation(){
    }
    
    /**
     * @param supplier
     * @param operator
     */
    public SupplierRecommendation(Supplier supplier, Long operator){
        this.supplier = supplier;
        this.creator = operator;
        this.createTime = new Date();
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        this.disabled = false;
    }
    
    /**
     * @param operator
     * @return
     */
    public SupplierRecommendation disable(Long operator) {
        this.disabled = true;
        this.lastOperator = operator;
        this.lastModifyTime = new Date();
        return this;
    }
    
    /**
     * 
     * @return
     */
    @Transient
    public boolean isValid() {
        return StringUtils.isNoneBlank(this.introduceForm) &&
               StringUtils.isNoneBlank(this.assessment) &&
               StringUtils.isNoneBlank(this.recommendation) &&
               (this.disabled == false);
    }
    
    /**
     * @return
     */
    public String inValidMessage() {
        if (StringUtils.isBlank(introduceForm)) {
            return "备选供应商引入评审申报表未上传";
        } else if (StringUtils.isBlank(assessment)) {
            return "现场评审得分结果未上传";
        } else if (StringUtils.isBlank(recommendation)) {
            return "推荐函未上传";
        } else {
            return null;
        }
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the supplier
     */
    public Supplier getSupplier() {
        return supplier;
    }

    /**
     * @return the introduceForm
     */
    public String getIntroduceForm() {
        return introduceForm;
    }

    /**
     * @return the assessment
     */
    public String getAssessment() {
        return assessment;
    }

    /**
     * @return the recommendation
     */
    public String getRecommendation() {
        return recommendation;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @return the lastModifyTime
     */
    public Date getLastModifyTime() {
        return lastModifyTime;
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @return the lastOperator
     */
    public Long getLastOperator() {
        return lastOperator;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param supplier the supplier to set
     */
    public void setSupplier(Supplier supplier) {
        this.supplier = supplier;
    }

    /**
     * @param introduceForm the introduceForm to set
     */
    public void setIntroduceForm(String introduceForm) {
        this.introduceForm = introduceForm;
    }

    /**
     * @param assessment the assessment to set
     */
    public void setAssessment(String assessment) {
        this.assessment = assessment;
    }

    /**
     * @param recommendation the recommendation to set
     */
    public void setRecommendation(String recommendation) {
        this.recommendation = recommendation;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    /**
     * @param lastModifyTime the lastModifyTime to set
     */
    public void setLastModifyTime(Date lastModifyTime) {
        this.lastModifyTime = lastModifyTime;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }

    /**
     * @param lastOperator the lastOperator to set
     */
    public void setLastOperator(Long lastOperator) {
        this.lastOperator = lastOperator;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }

}
